package com.quest.join;

/**
 * join作用是让出当前线程的资源，让其他线程来执行，可以实现顺序执行线程
 */
public class JoinTest {
    private static class Thread1 implements Runnable{
        @Override
        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("--Thread1 is running--");
        }
    }
    private static class Thread2 implements Runnable{
        @Override
        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("--Thread2 is running--");
        }
    }
    private static class Thread3 implements Runnable{
        @Override
        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("--Thread3 is running--");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Thread1());
        Thread t2 = new Thread(new Thread2());
        Thread t3 = new Thread(new Thread3());
        t1.start();
        t1.join();
        t2.start();
        t2.join();
        t3.start();
    }
}
